package com.example.book_test.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

@Slf4j
//@Component
@Aspect
@Order(1)
public class TimeAspect {
    @Pointcut("execution(* com.example.book_test.controller.*.*(..))")
    public void pt(){

    }
    @Around("pt()")
    public Object timeCost(ProceedingJoinPoint joinPoint) throws Throwable {
        long start = System.currentTimeMillis();
        Object result = joinPoint.proceed();
        long end = System.currentTimeMillis();
        log.info(joinPoint + "消耗时间：" + (end - start) + "ms");
        log.info("执行TimeAspect的TimestampCost方法");
        return result;
    }

    @Before("pt()")
    public void doBefore(){
        log.info("执行TimeAspect before");
    }

    @Before("pt()")
    public void doAfter(){
        log.info("执行TimeAspect after");
    }

}
